#include "Attribute.h"

Attribute::Attribute(QString name) : Parameter(name)
{
}

AccessModifier Attribute::getAccessModifier(){
    return accessModifier;
}

void Attribute::setAccessModifier(AccessModifier am)
{
    this->accessModifier = am;
}

QString Attribute::toXml()
{
    int nr = XMLSerializable::currentNumber++;
    QString xmi_id = "UMLAttribute."+QString::number(nr);
    QString visibility = (accessModifier == PROTECTED)?"protected" : ((accessModifier == PRIVATE)?"private":"public") ;
    QString isSpecification = "false";
    QString ownerScope = "instance";
    QString changeability = "changeable";
    QString targetScope = "instance";



    QString type = "";
    if(!clazz.getClassName().isEmpty())
    {
        type = XMLSerializable::typeNameToXmiId.value(clazz.getClassName(), "UMLClass."+QString::number(XMLSerializable::currentNumber++));
        XMLSerializable::typeNameToXmiId.insert(clazz.getClassName(), type);
    }

    QString owner = XMLSerializable::currentOwner;


    QString ret = "";

    ret += "          <UML:Attribute xmi.id=\""+xmi_id+"\" "\
           "name=\""+name+"\" "\
           "visibility=\""+visibility+"\" "\
           "isSpecification=\""+isSpecification+"\" "\
           "ownerScope=\""+ownerScope+"\" "\
           "changeability=\""+changeability+"\" "\
           "targetScope=\""+targetScope+"\" "\
           "type=\""+type+"\" "\
           "owner=\""+owner+"\" />\n";

    return ret;
}
